<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<title></title>
		<script type="text/javascript" src="../../js/boot.js"></script>
	</head>

	<body>
		<div class="mini-splitter" style="width: 100%; height: 100%;">
			<div size="240" showCollapseButton="true">
				<div class="mini-fit">
					<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
						<a class="mini-button" iconCls="icon-upload" plain="true" onclick="input()">导入</a>
						<a class="mini-button" iconCls="icon-download" plain="true" onclick="output()">导出</a>
					</div>
					<ul id="pageTree" class="mini-tree" style="width: 100%;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="departName" idField="departID" resultAsTree="false">
					</ul>
				</div>
			</div>

			<div showCollapseButton="true">
				<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
					<a class="mini-button" iconCls="icon-add" plain="true" onclick="addMenu()">新增</a>
					<a class="mini-button" iconCls="icon-remove" plain="true" onclick="removeMenu()">删除</a>
					<a class="mini-button" iconCls="icon-save" plain="true" onclick="saveMenu()">保存</a>
				</div>

				<div id="dataForm">
					<input id="parentID" name="parentID" class="mini-hidden" />
					<fieldset style="width: 98%;">
						<legend>
							<span>部门信息</span>
						</legend>
						<div class="fieldset-body">
							<table class="nteport-base-table2" style="width: 100%;">
								<tr>
									<td style="width: 10%; text-align: right;">编号：</td>
									<td style="width: 25%"><input id="departID" name="departID" class="mini-textbox" style="width: 90%" enabled="false" /></td>
									<td style="width: 10%; text-align: right;">名称：</td>
									<td style="width: 25%"><input id="departName" name="departName" class="mini-textbox" style="width: 90%" /></td>
								</tr>
								<tr>
									<td style="text-align: right;">部门位置：</td>
									<td><input id="departLocation" name="departLocation" class="mini-textbox" style="width: 90%" /></td>
									<td style="text-align: right;">部门描述：</td>
									<td><input id="departDiscrption" name="departDiscrption" class="mini-textbox" style="width: 90%" /></td>
								</tr>
								<tr>
									<td style="text-align: right;">排序：</td>
									<td><input id="sequence" name="sequence" class="mini-spinner" minValue="0" style="width:90%" /></td>
									<td style="text-align: right;"></td>
									<td></td>
								</tr>
							</table>
						</div>
					</fieldset>
				</div>

			</div>
		</div>
	</body>

	<script type="text/javascript">
		miniInit();

		var tree = mini.get("pageTree");
		var pageForm = new mini.Form("#dataForm");

		// 加载浅蓝色背景和去除滚动条
		$('.mini-splitter').addClass('bg');
		//$('.fieldset-body-body').addClass('bg');

		tree.url = http.getUrl("/sys/depart/list.do");
		tree.load(tree.url);

		var editNode = null; // 当前编辑的节点
		/*********************************************************
		 * 左侧目录树的鼠标点击事件
		 *********************************************************/
		tree.on("nodedblclick", function(e) {
			// debugger
			editNode = e.node;
			tree.loadNode(editNode);
			if(editNode) {
				pageForm.setData(editNode);
			}
		});

		/*********************************************************
		 * 操作方法
		 *********************************************************/
		/**
		 * 新增
		 */
		function addMenu() {
			var node = tree.getSelectedNode();
			if(node) {
				var newRow = {
					"parentID": node.departID
				};
				pageForm.setData(newRow);
				// alert(pageForm.getData().parentID);
			} else {
				miniui.showWarnMessageBox("请先选择部门创建的位置！");
			}
		}

		/**
		 * 保存
		 */
		function saveMenu() {
			var data = pageForm.getData();
			http.post("/sys/depart/save.do", data, function(page) {
				// 如果是修改保存，刷新父节点
				if(data.departID) {
					var parent = tree.getParentNode(editNode);
					tree.loadNode(parent);
				}
				// 如果是新增，刷新本节点的所有子节点
				else {
					tree.loadNode(editNode);
				}
			});
		}

		/**
		 * 删除
		 */
		function removeMenu() {
			var node = editNode;
			if(node) {
				mini.confirm("确定要删除" + editNode.departName + "吗？", "确定？", function(action) {
					if(action == "ok") {
						params = {
							"departID": node.departID
						}
						http.post("/sys/depart/delete.do", params, function(page) {
							tree.removeNode(node);
							pageForm.setData([]);
						});
					}
				});
			} else {
				showWarn("请先选择要删除的部门！");
			}
		}

		/**
		 * 导出
		 */
		function input() {}
		/**
		 * 导出
		 */
		function output() {
			params = {};
			http.post("/sys/depart/initial.do", params, function(page) {
			});
		}
	</script>

</html>